<!DOCTYPE html>
<html lang="en" ng-app="app">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/1.4.8/angular.js"></script>
</head>
<body>
<div ng-controller="myCtrl">
    <div>
        <input type="text" ng-model="num">
        <span>{{result}}</span>
    </div>
    <button ng-click="send()">send</button>
</div>
<script type="application/javascript">
    var app = angular.module("app", []);

    // 如果为post方式，则要重置config
    app.config(function ($httpProvider) {
        $httpProvider.defaults.headers.post = {
            'Content-type':'application/x-www-form-urlencoded'
        }
        $httpProvider.defaults.transformRequest = function (obj) {
            var arrStr = [];
            for(var p in obj){
                arrStr.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
            }
            return arrStr.join("&");
        }
    });

    app.controller("myCtrl", ["$scope", "$http", function ($scope, $http) {
        $scope.result = "";
        $scope.num = "";
        $scope.send = function () {
            $http({
                method:"POST",
                url:'http://localhost:8081/open/payment/testAngularPost.action',
                //如果是get方式，则为parms即可
                /*params:{
                    n:$scope.num
                }*/
                // 如果是post方式，则为data并且要重置transformRequest和Content-type
                data:{
                    n:$scope.num
                }
            }).success(function (data, status, headers, config){
                $scope.result = data;
                console.log("status:" + status);
                console.log("headers:" + headers);
                console.log("config:" + config);
            });
        };
    }]);
</script>
</body>
</html>